package com.ikun.core.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

/**
 * 配置原生 OpenApi3 文档的基本信息，knife4j 会自动读取该配置信息在首页展示。
 */
@Data
@Configuration
@Profile("dev")
@ConfigurationProperties(prefix = "ikun.app")
public class OpenApi3Config {

    private String name;
    private String version;
    private String description;
    private Contact contact;
    private License license;

    @Data
    public static class AppContact {
        private String name;
        private String email;
        private String url;
    }

    @Data
    public static class AppLicense {
        private String name;
        private String url;
    }


    public static final String[] SWAGGER_WHITELIST = {
            "/swagger-ui/**",
            "/swagger-ui/index.html",
            "/swagger-ui.html",
            "/swagger-ui.html/**",
            "/v3/api-docs",
            "/v3/api-docs/**",
            "/doc.html",
    };

    @Bean
    public OpenAPI customOpenAPI() {

        return new OpenAPI()
                .info(new Info()
                        .title(name + "接口文档") // 设置文档标题
                        .version(version) // 版本号
                        .description(description) // 详细描述
                        .contact(new Contact()
                                .name(contact.getName())
                                .email(contact.getEmail())
                                .url(contact.getUrl())) // 联系方式
                        .license(new License()
                                .name(license.getName())
                                .url(license.getUrl()))); // 许可证信息
    }


}
